<template>
	<view class="pages-mine" v-if="mineInfo.id">
		<image mode="aspectFill" lazy-load class="mine-bg abs" :src="configInfo[image_type[userPageType]]"></image>
		<view class="pd-lg" style="height: 252rpx" v-if="userPageType == 1">
			<view class="pt-lg" :class="[ { 'flex-warp': userInfo.nickName }, { 'flex-center': !userInfo.nickName } ]">
				<view class="avatar_view">
					<image mode="aspectFill" class="avatar radius"
						:src="mineInfo.avatarUrl || `/static/mine/default_user.png`">
					</image>
					<view class="text" v-if="mineInfo.is_admin == 1">
						代理商
					</view>
				</view>

				<block v-if="userInfo && !userInfo.nickName">
					<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
						:type="!userInfo.phone ? 'phone' : 'userInfo'" class="flex-1">
						<view class="flex-1 f-md-title text-bold ml-md"
							:style="{color:configInfo[font_type[userPageType]]}">立即登录</view>
					</auth>
				</block>
				<view class="flex-1 ml-md mt-sm rel" style="color:#000" v-else>
					<view class="flex-between">
						<view class="flex-y-center f-title text-bold">
							<view class="mr-sm max-500 ellipsis">
								{{ userInfo.nickName || '用户昵称' }}
							</view>
						</view>
						<view @tap.stop="$util.goUrl({url:`/user/pages/setting`})" class="notice-item ml-md">
							<i class="iconfont icon-xitong text-bold"></i>
						</view>
					</view>
					<view class="flex-between">
						<view class=" member-tag flex-center mt-sm pl-md pr-md f-caption radius "><i
								class="iconfont iconhuiyuanka mr-sm"></i>{{ mineInfo.coach_status === 2 ? mineInfo.coach_level.title || '技师' : '普通用户' }}
						</view>
						<view class="f-desc">
							<block v-if=" mineInfo.coach_status === 2 && mineInfo.service_time_long * 1 > 0 ">
								{{ `已服务${mineInfo.service_time_long}分钟` }}
							</block>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 用户 -->
		<!-- coach_status 1申请中，2已通过，3已取消授权，4已拒绝 -->
		<block v-if="userPageType == 1">
			<view class="flex-center ml-lg mr-lg pt-lg pb-lg pr-lg fill-base f-caption c-caption box-shadow radius-16 rel">
				<view class="share-list flex-between ml-lg" style="width: 32%">
					<view class="item-icon rel flex-center">
						<view class="item-icon item-icons radius-16 abs" :style="{background:primaryColor}"></view>
						<i class="iconfont icon-yue" :style="{color:primaryColor}"></i>
					</view>					
				</view>
				<view class="flex-column" style="width: 100%">
					<view class="f-caption">我的余额(元)</view>
					<view class="f-title c-title" :style="{ color: primaryColor }">￥{{ mineInfo.balance || 0 }}</view>					
				</view>
				<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
					:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="$util.goUrl({ url: `/user/pages/stored/list` })"
					style="width: 42%">
					<view class="item-btn flex-center f-paragraph c-base" :style="{ background: primaryColor }">立即充值</view>		
				</auth>
			</view>

			<view class="share-list flex-between mt-md">
				<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
					:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="$util.goUrl({ url: `/user/pages/collect` })" style="width: 50%">
					<view class="flex-between ml-lg mr-sm pt-lg pb-lg pl-md pr-sm fill-base f-caption c-desc box-shadow radius-16 ">					
						<view class="share-list flex-between" style="width: 32%">
							<view class="item-icon rel flex-center">
								<view class="item-icon item-icons radius-16 abs" :style="{background:primaryColor}"></view>
								<i class="iconfont icon-xinlijiankang" :style="{color:primaryColor}"></i>
							</view>					
						</view>						
						<view class="flex-column ml-lg" style="width: 100%">
							<view>我的收藏</view>
							<view class="f-title mb-sm" :style="{ color: primaryColor }">{{ mineInfo.collect_count || 0 }} 人</view>
						</view>
					</view>
				</auth>
				<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
					:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="$util.goUrl({ url: `/user/pages/coupon/list` })"
					style="width: 50%">
					<view class=" flex-between ml-sm mr-lg pt-lg pb-lg pl-md pr-sm fill-base f-caption c-desc box-shadow radius-16 ">
						<view class="share-list flex-between" style="width: 32%">
							<view class="item-icon rel flex-center">
								<view class="item-icon item-icons radius-16 abs" :style="{background:primaryColor}"></view>
								<i class="iconfont icon-youhuijuan" :style="{color:primaryColor}"></i>
							</view>					
						</view>	
						<view class="flex-column ml-lg" style="width: 100%">
							<view>我的优惠劵</view>
							<view class="f-title mb-sm" :style="{ color: primaryColor }">{{ mineInfo.coupon_count || 0 }} 张</view>
						</view>
					</view>
				</auth>
			</view>			
			<view class="flex-center mt-md ml-lg mr-lg radius-16">
				<auth v-if="mineInfo.is_fx==0" :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
					:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="toAtv" style="width: 100%">
					<view class="flex-between">
						<image class="coupon-img" style="width:100%;height: 90px;" src="/static/mine/coupon.png"></image>
					</view>
				</auth>
				<button open-type="share" class="shareItem" style="width: 100%;" >
					<image class="coupon-img" style="width:100%;height: 90px;" src="/static/mine/coupon.png"></image>
				</button>
			</view>
			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view @tap="toJumpAll(1)" class="menu-title flex-between pl-lg pr-md b-1px-b">
					<view class="f-paragraph c-title text-bold">我的订单</view>
					<view class="flex-y-center f-caption c-paragraph">全部订单<i class="iconfont icon-right"></i></view>
				</view>
				<view class="flex-warp pt-lg pb-lg">
					<view @tap.stop="toJump('orderList', index)"
						class="item-child flex-center flex-column f-caption c-paragraph"
						v-for="(item, index) in orderList" :key="index">
						<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
						<view class="mt-sm">{{ item.text }}</view>
					</view>
				</view>
			</view>
			<view class="mine-tool-list mine-menu-list fill-base radius-16">
				<view class="menu-title flex-between pl-lg pr-md b-1px-b">
					<view class="f-paragraph c-title text-bold">我的功能</view>
				</view>
				<block v-for="(item, index) in mineInfo.is_fx ? distributionList : distributionApplyList"
					:key="index">	
					<view @tap.stop="toJump(mineInfo.is_fx ?'distributionList':'distributionApplyList', index)" 
						class="list-item pt-lg pb-lg ml-lg mr-lg flex-center b-1px-b"
						v-if="item.text == '绑定技师'?mineInfo.is_admin == 1?true:false:true">
						<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
						<view class="flex-1 flex-between ml-md">
							<view class="f-paragraph c-title">{{ item.text }}</view>
							<i class="iconfont" :class="[{'icon-right':item.text}]" :style="{fontSize:item.text}"></i>
							</i>
						</view>
					</view>
				</block>				
				<block v-for="(item, index) in toolList" :key="index">
					<!-- #ifdef MP-WEIXIN -->
					<button :open-type="configInfo.im_type == 2 ?'contact':''" class="clear-btn"
						v-if="item.text == '联系客服' && configInfo.im_type == 2">
						<view class="list-item pt-lg pb-lg ml-lg mr-lg  flex-center" :class="[{ 'b-1px-t': index != 0 }]">
							<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
							<view class="flex-1 flex-between ml-md">
								<view class="f-paragraph c-title">{{ item.text }}</view>
								<i class="iconfont icon-right"></i>
							</view>
						</view>
					</button>
					<block v-else>
						<auth :needAuth="userInfo && (!userInfo.phone || !userInfo.nickName)" :must="true"
							:type="!userInfo.phone ? 'phone' : 'userInfo'" @go="toJump('toolList', index)">
							<view class="list-item pt-lg pb-lg ml-lg mr-lg flex-center" :class="[{ 'b-1px-t': index != 0 }]">
								<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
								<view class="flex-1 flex-between ml-md">
									<view class="f-paragraph c-title">{{ item.text }}</view>
									<i class="iconfont" :class="[{'icon-right':item.text}]" :style="{fontSize:item.text}"></i>
								</view>
							</view>
						</auth>
					</block>
					<!-- #endif -->
					<!-- #ifndef MP-WEIXIN -->
					<view @tap.stop="toJump('toolList', index)" class="list-item pt-lg pb-lg ml-lg mr-lg flex-center" :class="[{ 'b-1px-t': index != 0 }]">
						<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
						<view class="flex-1 flex-between ml-md">
							<view class="f-paragraph c-title">{{ item.text }}</view>
							<i class="iconfont" :class="[{'icon-right':item.text}]" :style="{fontSize:item.text}"></i>
						</view>
					</view>
					<!-- #endif -->
				</block>				
				<view @tap.stop="toChange" class="list-item pd-lg flex-center b-1px-t"
					v-if="mineInfo.coach_status == 2 || mineInfo.coach_status == 3">
					<i class="iconfont icon-qiehuan" :style="{color:primaryColor}"></i>
					<view class="flex-1 flex-between ml-md">
						<view class="f-paragraph c-title">切换技师端</view>
						<i class="iconfont icon-switch c-caption"></i>
					</view>
				</view>
			</view>
		</block>
		
		<!-- 技师端 -->
		<block v-if="userPageType == 2">
			<view style="height: 139px;">	
					
			</view>	
						
			<view class="mine-count-list rel box-shadow ml-lg mr-lg fill-base f-caption c-caption radius-16">		
				<view class="pd-lg" style="height: 272rpx">
					<view class="pt-lg" :class="[ { 'flex-warp': userInfo.nickName }, { 'flex-center': !userInfo.nickName } ]">
						<view class="avatar_view">
							<image mode="aspectFill" class="avatar radius"
								:src="coach_info.work_img || `/static/mine/default_user.png`">
							</image>
						</view>
						<view class="flex-1 ml-md mt-sm rel">
							<view class="flex-between">
								<view class="flex-y-center f-title text-bold">
									<view class="mr-sm max-500 ellipsis">{{ coach_info.coach_name }}</view>
									<view class="mr-sm max-500 ellipsis" style="font-weight: 500;
									font-size: 26rpx;
									margin-left: 40rpx;
									width: 80rpx;
									height: 40rpx;
									background: #FF5722;
									color: #fff;
									text-align: center;
									border-radius: 20rpx;
								">{{ coach_info.is_work ? '在线' : '隐身' }}</view>
								</view>
								<view @tap.stop="$util.goUrl({url:`/technician/pages/apply?is_edit=1`})" 
									class="flex-y-center f-paragraph c-caption">个人信息<i class="iconfont icon-right f-caption"></i>
								</view>
							</view>							
							<view class="flex-between">
								<view class=" member-tags c-base flex-center mt-sm pl-md pr-md f-caption radius " :style="{ background: primaryColor }"><i
										class="iconfont iconhuiyuanka mr-sm"></i>{{ mineInfo.coach_status === 2 ? mineInfo.coach_level.title || '技师' : '普通用户' }}
								</view>
								<view class="f-desc">
									<block v-if=" mineInfo.coach_status === 2 && mineInfo.service_time_long * 1 > 0 ">
										{{ `已服务${mineInfo.service_time_long}分钟` }}
									</block>
								</view>
							</view>								
							<view class="cancel-auth iconfont icon-biaoqian c-caption flex-center abs"
								v-if="mineInfo.coach_status == 3">
								<view class="text-bold f-icontext abs">取消授权</view>
							</view>											
							<view @tap.stop="toChooseLocation" class="flex-x-center mt-md f-caption item-img rel radius" style="height: 72rpx"
								v-if="mineInfo.coach_status == 2">								
								<i class="iconfont iconjuli" :style="{color:primaryColor}"></i>
								<view class="mr-sm" :style="{color:primaryColor}">当前</view>
								<!-- 实时地址： -->
								<view class="flex-1 ellipsis-2">{{ coach_info.address }}</view>
							</view>							
							<view class="mt-md" style="height: 72rpx" v-else></view>
						</view>
					</view>
				</view>	
			</view>	
			<view class="share-list flex-between mt-md">
				<view @tap.stop="$util.goUrl({ url: `/technician/pages/income/index` })" style="width: 50%">
					<view
						class="mine-count-list flex-between rel box-shadow ml-lg mr-sm fill-base f-caption c-caption radius-16  pt-lg pb-lg pl-md pr-sm">						
						<view>
							<view class="f-paragraph mb-sm">服务收入(元)</view>
							<view class="f-title c-title" :style="{ color: primaryColor }">￥{{ coach_info.service_price || 0 }}</view>					
						</view>												
						<view class="cash-btn flex-center c-base f-paragraph radius" 
						:style="{ background: primaryColor }">提现</view>
					</view>
				</view>
				<view @tap.stop=" $util.goUrl({ url: `/user/pages/cash-out?type=carfee` })" style="width: 50%">
					<view
						class="mine-count-list flex-between ml-sm mr-lg pt-lg pb-lg pl-md pr-sm fill-base f-caption c-caption box-shadow radius-16 ">
						<view>
							<view class="f-paragraph mb-sm">车费(元)</view>
							<view class="f-title c-title" :style="{ color: primaryColor }">￥{{ coach_info.car_price || 0 }}</view>
						</view>
						<view class="cash-btn flex-center c-base f-paragraph radius" 
						:style="{ background: primaryColor }">提现</view>
					</view>
				</view>
			</view>	
			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view class="menu-title flex-between pl-lg pr-sm b-1px-b">
					<view class="f-paragraph c-title text-bold">我的订单</view>
				</view>
				<view class="flex-warp pt-lg pb-lg">
					<view @tap.stop="toJump('orderList2', index)"
						class="item-child flex-center flex-column f-caption c-paragraph" style="width: 33.3%"
						v-for="(item, index) in orderList2" :key="index">
						<view class="item-img rel flex-center radius">
							<view class="item-img radius abs" :style="{background:primaryColor}"></view>
							<i class="iconfont c-title" :class="item.icon" :style="{color:primaryColor}"></i>
						</view>
						<view class="mt-sm">{{ item.text }}</view>
					</view>
					<view style="
					width: 50rpx;
					height: 50rpx;
					background-color: red;
					color: #fff;
					text-align: center;
					line-height: 50rpx;
					font-size: 26rpx;
					border-radius: 50%;
					font-weight: 600;
					position: relative;
					top: -160rpx;
					left: 150rpx;">{{agent_order_count < 100 ? agent_order_count : '99+'}}
					</view>
				</view>
			</view>
			<view class="mine-menu-list box-shadow fill-base radius-16">
				<view style="height: 109px;">	
					<view class="flex-center ml-lg mr-lg pt-lg pb-md c-black f-caption radius-16 rel">
						<view @tap.stop=" $util.goUrl({ url: `/technician/pages/time-manage` })" style="width: 50%">
							<view class="flex-center flex-column f-caption c-black">
								<view class="share-list flex-between" style="width: 32%">
									<view class="item-icon rel flex-center">
										<i class="iconfont iconshijianguanli"></i>
									</view>					
								</view>			
								<view class="f-paragraph">时间管理</view> 
							</view>
						</view>
						<view @tap.stop=" $util.goUrl({ url: `/technician/pages/income/car-fee-record` })" style="width: 50%">
							<view class="flex-center flex-column f-caption c-black">					
								<view class="share-list flex-between" style="width: 32%">
									<view class="item-icon rel flex-center">
										<i class="iconfont icon-dingdan-blue-copy"></i>
									</view>					
								</view>							
								<view class="f-paragraph">提现记录</view>
							</view>
						</view>
						<view @tap.stop="toHelp" style="width: 50%">
							<view class="flex-center flex-column f-caption c-black">
						
								<view class="share-list flex-between" style="width: 32%">
									<view class="item-icon rel flex-center">
										<i class="iconfont iconjingbao"></i>
									</view>					
								</view>							
								<view class="f-paragraph">一键报警</view>
							</view>
						</view>	
					</view>			
				</view>	
			</view>
			
			<view class="mine-tool-list box-shadow fill-base radius-16">
				<view @tap.stop="toJump('toolList2', index)" class="list-item pt-lg pb-lg ml-lg mr-lg flex-center"
					:class="[{ 'b-1px-t': index != 0 }]" v-for="(item, index) in toolList2" :key="index">
					<i class="iconfont" :class="item.icon" :style="{color:primaryColor}"></i>
					<view class="flex-1 flex-between ml-md">
						<view class="f-paragraph c-title">{{ item.text }}</view>
						<block v-if="item.url == 'change'">
							<i class="iconfont icon-switch c-caption"></i>
						</block>
						<i class="iconfont icon-right" v-else></i>
					</view>
				</view>
			</view>	
		</block>
		<view class="space-footer"></view>
		<view :style="{height: `${configInfo.tabbarHeight}px`}"></view>
		<tabbar :cur="3"></tabbar>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	import tabbar from "@/components/tabbar.vue"
	export default {
		components: {
			tabbar
		},
		data() {
			return {
				options: {},
				// 我的订单
				orderList: [{
					icon: 'icon-daizhifu1',
					text: '待支付',
					url: '/pages/order?tab=1'
				}, {
					icon: 'icon-daiqueren',
					text: '待服务',
					url: '/pages/order?tab=2'
				}, {
					icon: 'icon-kangfuliliaoke',
					text: '服务中',
					url: '/pages/order?tab=3'
				}, {
					icon: 'icon-daipingjia2',
					text: '待评价',
					url: '/pages/order?tab=4'
				}, {
					icon: 'icontuikuan',
					text: '退款/售后',
					url: '/user/pages/refund/list'
				}],
				orderList2: [{
					icon: 'icon-dingdanjihuo',
					text: '待接单',
					url: '/technician/pages/order/list'
				}, {
					icon: 'iconyijiedan',
					text: '待服务',
					url: '/technician/pages/order/list?tab=1'
				}, {
					icon: 'icon-kangfuliliaoke',
					text: '服务中',
					url: '/technician/pages/order/list?tab=2'
				}],
				// 分享赚钱
				distributionList: [{
					icon: 'icon-shouyi',
					text: '我的收益',
					url: '/user/pages/distribution/income'
				}, 
				{
					icon: 'icon-tuiguang',
					text: '推广海报',
					url: '/user/pages/distribution/poster'
				}, 
				{
					icon: 'icon-wodefensi1',
					text: '我的粉丝',
					url: '/user/pages/distribution/team'
				}, {
					icon: 'icon-jishi',
					text: '绑定技师',
					url: '/user/pages/distribution/bind-technician'
				}],
				distributionApplyList: [{
					icon: 'icon-fenxiao',
					text: '申请分销商',
					url: '/user/pages/distribution/apply'
				}, {
					icon: 'icon-jishi',
					text: '绑定技师',
					url: '/user/pages/distribution/bind-technician'
				}],
				toolList: [{
					icon: 'icon-dizhi',
					text: '地址管理',
					url: '/user/pages/address/list'
				}, {
					icon: 'icon-kefu',
					text: '联系客服',
					url: ''
				}],
				toolList2: [{
					icon: 'icon-qiehuan',
					text: '切换用户端',
					url: 'change'
				}],
				image_type: {
					1: 'user_image',
					2: 'coach_image'
				},
				font_type: {
					1: 'user_font_color',
					2: 'coach_font_color'
				},
				coach_info: {},
				showAuth: false,
				offsetL: 360,
				offsetT: 0,
				agent_order_count:0
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
			configInfo: state => state.config.configInfo,
			commonOptions: state => state.user.commonOptions,
			userInfo: state => state.user.userInfo,
			userPageType: state => state.user.userPageType,
			mineInfo: state => state.user.mineInfo,
		}),
		async onShow(){
			if(!this.$store.state.user.autograph){
				let url = `/pages/phonelogin`
				this.$util.goUrl({
					url
				})
				return false;
				
			}
			if(this.userPageType == 2){
				this.getnewList();
			}
			
		},
		onLoad(options) {
			this.options = options
			let {
				type = 0
			} = options
			if (type) {
				this.updateUserItem({
					key: 'userPageType',
					val: type
				})
			}
			if (!this.mineInfo.id) {
				this.$util.showLoading()
			}
			this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh();
			uni.stopPullDownRefresh()
			if(this.userPageType == 2){
				this.getnewList();
			}
		},
		// 1.发送给朋友
		onShareAppMessage(){
			var path = `/pages/phonelogin?pid=${this.mineInfo.id}`
			this.$util.log(path)
			return {
				title: '',
				imageUrl: '',
				path,
			}
		},
		methods: {
			...mapActions(['getConfigInfo', 'getMineInfo', 'getAuthUserProfile', 'updateCommonOptions', 'toPlayAudio']),
			...mapMutations(['updateUserItem']),
			async initIndex(refresh = false) {
				// #ifdef H5
				if (!refresh && this.$jweixin.isWechat()) {
					await this.$jweixin.initJssdk();
					this.$jweixin.wxReady(() => {
						this.$jweixin.hideOptionMenu()
					})
				}
				// #endif

				if (!this.configInfo.id || refresh) {
					await this.getConfigInfo()
				}
				await this.getMineInfo()
				this.$util.setNavigationBarColor({
					bg: this.primaryColor
				})

				let {
					fx_check
				} = this.configInfo
				let {
					coach_status,
					fx_status
				} = this.mineInfo

				let val = this.$util.deepCopy(this.mineInfo)
				val.is_fx = !fx_check || (fx_check && fx_status == 2)
				this.updateUserItem({
					key: 'mineInfo',
					val
				})
				this.updateUserItem({
					key: 'userPageType',
					val: coach_status == 2 || coach_status == 3 ? this.userPageType : 1
				})

				let arr = ['coach_status', 'channel_status']
				let textArr = {
					coach_status: {
						text: '申请技师',
						list: {
							icon: 'icon-jishi',
							text: '申请技师',
							url: '/user/pages/apply'
						}
					},
					channel_status: {
						text: '申请渠道商',
						list: {
							icon: 'icon-fensi1',
							text: '申请渠道商',
							url: '/user/pages/channel/apply'
						},
						list2: {
							icon: 'icon-fensi1',
							text: '我是渠道商',
							url: '/user/pages/channel/income'
						}
					}
				}
				arr.map(item => {
					if (this.mineInfo[item] != 2) {
						let arr = this.toolList.filter(aitem => {
							return aitem.text === textArr[item].text
						})
						if (arr.length === 0) {
							this.toolList.unshift(textArr[item].list)
						}
						if (item === 'channel_status') {
							let aindex = this.toolList.findIndex(aitem => {
								return aitem.text === '我是渠道商'
							})
							if (aindex != -1) {
								this.toolList.splice(aindex, 1)
							}
						}
					} else {
						this.toolList.map((aitem, aindex) => {
							if (aitem.text === textArr[item].text) {
								this.toolList.splice(aindex, 1)
							}
						})
						if (item === 'channel_status') {
							let arr = this.toolList.filter(aitem => {
								return aitem.text === '我是渠道商'
							})
							if (arr.length === 0) {
								this.toolList.unshift(textArr[item].list2)
							}
						}
					}
				})

				if (coach_status == 2 || coach_status == 3) {
					await this.getCoachInfo()
				}
				this.$util.hideAll()
			},
			initRefresh() {
				this.initIndex(true)
			},
			async getCoachInfo() {
				this.coach_info = await this.$api.technician.coachInfo()
			},
			// 更新用户信息
			async authUserProfile(e) {
				// #ifdef APP-PLUS
				uni.getUserInfo({
					provider: 'weixin',
					success: res => {
						let {
							userInfo = {}
						} = res
						this.toUpdateUserInfo(userInfo)
					}
				})
				// #endif
				// #ifndef APP-PLUS
				uni.getUserProfile({
					desc: '用于完善个人资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
					success: (res) => {
						let {
							userInfo = {},
								encryptedData,
								iv,
						} = res
						let param = Object.assign({}, userInfo, {
							encryptedData,
							iv,
						});
						this.toUpdateUserInfo(param)
					},
					fail: (res) => {
						console.log(res, "=====fail");
						this.toUpdateUserInfo()
					}
				})
				// #endif
			},
			async toUpdateUserInfo(userInfo = {}) {
				let {
					pMust
				} = this
				if (userInfo.nickName) {
					this.$util.showLoading({
						title: '更新中'
					})
					let {
						coupon_atv_id = 0
					} = this.commonOptions
					userInfo.coupon_atv_id = coupon_atv_id
					await this.getAuthUserProfile(userInfo)
					setTimeout(() => {
						this.$util.hideAll()
					}, 1000)
				}
			},
			// 选择地区
			async toChooseLocation(e) {
				await this.$util.checkAuth({
					type: 'userLocation'
				})
				let [, {
					address = '',
					longitude,
					latitude
				}] = await uni.chooseLocation();
				if (!address) return
				await this.$api.technician.coachUpdate({
					address,
					lng: longitude,
					lat: latitude
				})
				this.coach_info.address = address
				this.$util.showToast({
					title: `更新成功`
				})
			},
			// 跳转页面
			toJumpAll(key) {
				let url = {
					1: `/pages/order`,
					2: `/technician/pages/order/list`
				}
				let openType = {
					1: `reLaunch`,
					2: `navigateTo`
				}
				this.$util.goUrl({
					url: url[key],
					openType: openType[key]
				})
			},
			toJump(key, index) {
				let {
					url,
					text
				} = this[key][index]
				if (['申请技师', '申请分销商', '申请渠道商'].includes(text)) {
					this.toApply(text == '申请技师' ? 1 : text == '申请分销商' ? 2 : 3)
					return
				}
				if (text == '切换用户端') {
					this.toChange()
					return
				}
				if (text == '联系客服') {
					let {
						mobile: url,
						im_type
					} = this.configInfo
					// #ifdef MP-WEIXIN
					if (im_type == 2) return
					// #endif
					this.$util.goUrl({
						url,
						openType: 'call'

					})
					return
				}
				let openType = key == 'orderList' && index !== 4 ? `reLaunch` : 'navigateTo'
				this.$util.log(url)
				this.$util.goUrl({
					url,
					openType
				})
			},
			async toAtv() {
				
				if (!this.mineInfo.is_atv) {
					console.log(this.mineInfo);
					this.$util.showToast({
						title: `暂无活动`
					})
					return
				}
				let options = this.commonOptions
				options.coupon_atv_id = 0
				await this.updateCommonOptions(options)
				this.$util.goUrl({
					url: `/user/pages/coupon/share`
				})
			},
			// 申请技师/分销商/渠道商
			async toApply(type) {
				let {
					coach_status = -1,
						fx_status = -1,
						channel_status = -1
				} = this.mineInfo
				let status = type == 1 ? coach_status : type == 2 ? fx_status :
					channel_status
				let page = {
					1: `/technician/pages/apply`,
					2: `/user/pages/distribution/apply`,
					3: `/user/pages/channel/apply`
				}
				// -1未申请，1审核中，2审核通过，3取消授权，4审核失败
				let url = status == -1 ? page[type] :
					`/user/pages/apply-result?type=${type}`
				this.$util.log(url)
				this.$util.goUrl({
					url
				})
			},
			// 切换用户/技师端
			async toChange() {

				let {
					userPageType = 1
				} = this
				console.log('这里看过来');
				console.log(userPageType);
				if (userPageType == 2) {
					await this.getCoachInfo()
					this.updateUserItem({
						key: 'userPageType',
						val: userPageType == 2 ? 1 : 2
					})
				}else{
					
					var that = this;
					
					//切换技师端的时候授权接受订阅消息
					wx.requestSubscribeMessage({
						tmplIds: ['Nfy3EBuwdVIcFNoLz6nE4qYf_ZWkjXxCKizmiXpgxXI'],
						success (res) { 
							if(res.Nfy3EBuwdVIcFNoLz6nE4qYf_ZWkjXxCKizmiXpgxXI=='accept'){
								console.log('接受了订阅')
							}else{
								console.log('拒绝了订阅')
							}
							that.updateUserItem({
								key: 'userPageType',
								val: userPageType == 2 ? 1 : 2
							})
							
						}
					})	
					this.getnewList();
					
				}
			},
			async getnewList(){
				var param = {page:1,pay_type:2};
				let newList = await this.$api.technician.orderList(param);
				this.agent_order_count = newList.agent_order_count;
			},
			onChange(e) {
				let {
					x,
					y
				} = e.detail
				this.$nextTick(() => {
					this.offsetL = x
					this.offsetT = y
				})
			},
			// 求助
			async toHelp() {
				await this.$api.technician.police()
				this.$util.showToast({
					title: `求救成功`
				})
			}
		}
	}
</script>

<style lang="scss">
	.f_r_sb_c {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.pages-mine {
		.mine-bg {
			width: 100%;
			height: 318rpx;
			z-index: -1;
		}

		.mine-master-bg {
			width: 100%;
			height: 514rpx;
			z-index: -1;
		}

		.avatar_view {
			width: 120rpx;
			height: 120rpx;
			position: relative;

			.avatar {
				width: 120rpx;
				height: 120rpx;
				overflow: hidden;

				open-data {
					width: 120rpx;
					height: 120rpx;
				}
			}

			.text {
				width: 110rpx;
				position: absolute;
				bottom: -5rpx;
				left: 5rpx;
				height: 36rpx;
				line-height: 36rpx;
				background: #FFFFFF;
				border-radius: 18rpx;
				color: #A40035;
				font-size: 24rpx;
				text-align: center;
			}
		}


		.member-tag {
			min-width: 168rpx;
			height: 42rpx;
			background: rgba(255, 255, 255, 0.5);

			.iconfont {
				font-size: 28rpx;
			}
		}
		
		.member-tags {
			min-width: 168rpx;
			height: 42rpx;

			.iconfont {
				font-size: 28rpx;
			}
		}
		
		.icon-shuaxin,
		.icon-xitong {
			font-size: 40rpx;
		}

		.share-img {
			width: 86rpx;
			height: 86rpx;
		}

		.mine-count-list {
			.cancel-auth {
				width: 600rpx;
				height: 40rpx;
				font-size: 100rpx;
				top: 100rpx;
				left: 150rpx;

				.text-bold {
					height: 26rpx;
					transform: rotate(-32deg);
				}
			}

			.cash-btn {
				width: 108rpx;
				height: 52rpx;
				transform: rotateZ(360deg);
			}

			.icon-right {
				font-size: 28rpx;
			}
		}
		
		.item-btn {
			width: 150rpx;
			height: 52rpx;
			border-radius: 100rpx;
		}
		
		.share-list {
			.coupon-img {
				width: 97rpx;
				height: 87rpx;
			}

			.item-icon {
				width: 100rpx;
				height: 100rpx;

				.iconfont {
					font-size: 62rpx;
				}

				.item-icon {
					top: 0;
					left: 0;
					opacity: 0.1;
				}
			}
		}

		.mine-menu-list {
			margin: 20rpx 30rpx 0 30rpx;

			.menu-title {
				height: 90rpx;

				.iconfont {
					font-size: 24rpx;
				}
			}

			.item-child {
				width: 20%;
				margin: 10rpx 0;

				.iconfont {
					font-size: 52rpx;
				}

				.item-img {
					width: 88rpx;
					height: 88rpx;

					.iconfont {
						font-size: 44rpx;
					}

					.item-img {
						top: 0;
						left: 0;
						opacity: 0.1;
					}
				}

			}
		}

		.mine-tool-list {
			margin: 20rpx 30rpx 0 30rpx;
			box-shadow: 0px 3px 6px 0px rgba(227, 227, 227, 0.47);

			.list-item {
				.iconfont {
					font-size: 42rpx;
				}

				.icon-right {
					font-size: 28rpx;
				}

				.icon-switch {
					font-size: 70rpx;
					line-height: 48rpx;
				}
			}

			.list-item.b-1px-t:before {
				left: 60rpx;
			}
		}

		.help-img-info {
			width: 130rpx;
			height: 130rpx;
			right: 30rpx;
			
			.bg-img {
				width: 130rpx;
				height: 130rpx;
				opacity: 0.4;
				top: 0;
				left: 0;
			}

			.help-info {
				width: 130rpx;
				height: 130rpx;
				opacity: 1;
				top: 0;
				left: 0;

				.help-img {
					width: 118rpx;
					height: 118rpx;

					.iconfont {
						font-size: 44rpx;
						margin-bottom: 4rpx;
					}
				}
			}
		}		
	}
</style>
